package com.blog.conf;

import com.blog.conf.intercepter.LoginIntercepter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;


@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Resource
    private LoginIntercepter loginIntercepter;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        //添加静态资源文件，外部可以直接访问地址
        registry.addResourceHandler("/upload/**").addResourceLocations("/upload/");
        super.addResourceHandlers(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(loginIntercepter).addPathPatterns("/admin/**")
                .excludePathPatterns("/auth/login");
    }
}
